<template>
  <div class="small-menu">
    <ul class="menu">
      <div class="arrow" v-if="!isShowSecondMenu" @click="showSecondMenu"></div>
      <div class="arrow-g" v-else @click="showSecondMenu"></div>
      <li class="list" v-for="(item,i) in menu" :key="item.id"
        :class="{active:currentIndex === i}" @click="onClick(i)">
        <a href="#">{{item.title}}</a>
        <div v-show=" isShowSecondMenu">
          <ul v-if="item.children">
            <li class="child-menu" v-for="item in item.children" :key="item.id">
              <a href="#">{{item.title}}</a>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'SmallMenu',
  data() {
    return {
      menu: [
        { id: 1, title: '首页' },
        {
          id: 2,
          title: '品牌网站',
          children: [
            { id: 21, title: '集团平台' },
            { id: 22, title: '服装服饰' },
            { id: 23, title: '珠宝美妆' },
            { id: 24, title: '地产家居' },
            { id: 25, title: '艺术设计' },
            { id: 26, title: '其他' }
          ]
        },
        { id: 3, title: '电商解决方案' },
        { id: 4, title: '微信营销' },
        { id: 5, title: '小程序' },
        { id: 6, title: '关于我们' }
      ],
      isShowSecondMenu: false,
      currentIndex: 0
    }
  },
  methods: {
    onClick(i) {
      if (i === 1) {
        this.isShowSecondMenu = !this.isShowSecondMenu
        if (!this.isShowSecondMenu) {
          this.currentIndex = null
          return
        }
      }
      this.currentIndex = i
    },
    showSecondMenu() {
      this.isShowSecondMenu ? this.currentIndex = null : this.currentIndex = 1
      this.isShowSecondMenu = !this.isShowSecondMenu
    }
  }
}
</script>

<style lang='less' scoped>
.small-menu {
  z-index: 998;
  background-color: #fff;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  text-align: center;
  .menu {
    position: relative;
    top: 20%;
    .list {
      font-size: 16px;
      line-height: 30px;
      margin-bottom: 10px;
      a {
        color: #000000;
      }
      .child-menu {
        line-height: 28px;
        font-size: 12px;
        a {
          color: #666666;
        }
      }
    }
    .active {
      a {
        color: #11adbb;
      }
    }

    .arrow {
      width: 22px;
      height: 22px;
      background: url('../../assets/wap-btn-normal.png');
      background-size: 22px 22px;
      position: absolute;
      right: 34%;
      top: 44px;
    }
    .arrow-g {
      width: 22px;
      height: 22px;
      background: url('../../assets/wap-btn.png');
      background-size: 22px 22px;
      position: absolute;
      right: 34%;
      top: 44px;
    }
  }
}
</style>
